/**
 * 函数
 */
// 自定义函数
function add(x: number, y: number): number {
  return x + y;
}
// 函数变量定义
let myAdd = function (x: number, y: number): number {
  return x + y;
};

// 箭头函数
let myAdd2: (baseValue: number, increment: number) => number =
  function (x: number, y: number): number {
    return x + y;
  };


/**
 * 可选参数和默认参数
 *  */ 
// 可选参数
function buildName(firstName: string, lastName?: string) {
  if (lastName) return firstName + " " + lastName;
  else return firstName;
}
// 默认参数
function buildName2(firstName: string, lastName = "Smith") {
  return firstName + " " + lastName;
}



// 接口和箭头函数结合
interface t {
  name: string;
  age: number;
  hobby: Array<string>;
  say:(str:string)=>void;
}
let t1: t = {
  name: "张三",
  age: 20,
  hobby: ["吃饭", "睡觉"],
  say: (str: string) => {
    console.log(`${t1.name}说${str}`);
  },
};
t1.say("你好")

